package com.ceshi.service;

import javax.servlet.http.HttpSession;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

import com.ceshi.dao.UserDao;
import com.ceshi.meta.User;

@Service
public class UserService {
	private User user;
	public int loginvalid(String userName, String password) {
		ApplicationContext context = new ClassPathXmlApplicationContext("application-context.xml");
		UserDao userdao = context.getBean(UserDao.class);

		System.out.println("login:" + userName + "|" + password);

		user = userdao.getUser(userName);
		if (user == null) {

			System.out.println("登录失败，用户不存在");
			return -1;

		} else if (user.getUserPassword().equals(password)) {

			System.out.println("登录成功:" + userName);
			return 0;

		} else {

			System.out.println("登录失败，密码错误");
			return 1;
			
		}
	}
	
	public User getUser() {
		
		return user;
		
	}
}
